# -*- encoding: utf8 -*-

DAILY_DEVICE_REPORT_V2 = {
    'group_by': '_chn.keyword',
    'target_event_id': ['recharge', 'withdraw', 'bet_order', 'active', 'register', 'bind'],
    'values': [
        {
            "value_id": "new_device",
            "target_value": "_aid.keyword",
            "value_name": "新增设备",
            "filter": [
                {'terms': {'_event_id': ['register']}},
            ],
            "operation": "cardinality",
        },
        {
            "value_id": "new_register_device",
            "target_value": "_aid.keyword",
            "value_name": "首日注册设备",
            "filter": [
                {'term': {'_event_id': 'bind'}},
                {'term': {'_is_new_user': 1}}
            ],
            "operation": "cardinality",
        },
        {
            "value_id": "acc_register_device",
            "target_value": "_aid.keyword",
            "value_name": "累计注册设备数",
            "filter": [
                {'term': {'_event_id': 'bind'}},
            ],
            "time_range": {
                "_registered_at": [0, 0],
                "_event_time": [0, '+']
            },
            "operation": "cardinality",
        },
        {
            "value_id": "stay_2_device",
            "target_value": "_aid.keyword",
            "value_name": "设备次留设备数",
            "filter": [
                {"term": {"_event_id": "active"}},
                {"term": {"_active_days": 1}}
            ],
            "time_range": {
                "_event_time": [1, 1]
            },
            "operation": "cardinality",
        },
        {
            "value_id": "stay_3_device",
            "target_value": "_aid.keyword",
            "value_name": "设备3日留存设备数",
            "filter": [
                {"term": {"_event_id": "active"}},
                {"term": {"_active_days": 2}}
            ],
            "time_range": {
                "_event_time": [2, 2]
            },
            "operation": "cardinality",
        },
        {
            "value_id": "stay_7_device",
            "target_value": "_aid.keyword",
            "value_name": "设备7日留存设备数",
            "filter": [
                {"term": {"_event_id": "active"}},
                {"term": {"_active_days": 6}}
            ],
            "time_range": {
                "_event_time": [6, 6]
            },
            "operation": "cardinality",
        },
        {
            "value_id": "stay_14_device",
            "target_value": "_aid.keyword",
            "value_name": "设备14日留存设备数",
            "filter": [
                {"term": {"_event_id": "active"}},
                {"term": {"_active_days": 13}}
            ],
            "time_range": {
                "_event_time": [13, 13]
            },
            "operation": "cardinality",
        },
        {
            "value_id": "stay_30_device",
            "target_value": "_aid.keyword",
            "value_name": "设备30日留存设备数",
            "filter": [
                {"term": {"_event_id": "active"}},
                {"term": {"_active_days": 29}}
            ],
            "time_range": {
                "_event_time": [29, 29]
            },
            "operation": "cardinality",
        },
        {
            "value_id": "recharge_new_user",
            "target_value": "_user_id",
            "value_name": "新增用户付费账号",
            "filter": [
                {"term": {"_event_id": "recharge"}},
                {"term": {"_is_new_user": 1}}
            ],
            "operation": "cardinality",
        },
        {
            "value_id": "new_recharge_amount",
            "target_value": "recharge_price",
            "value_name": "新增用户付费金额",
            "filter": [
                {"term": {"_event_id": "recharge"}},
                {"term": {"_is_new_user": 1}}
            ],
        },
        {
            "value_id": "acc_recharge_user",
            "target_value": "_user_id",
            "value_name": "累计充值账号",
            "filter": [
                {"term": {"_event_id": "recharge"}}
            ],
            "time_range": {
                "_event_time": ['-', 0],
            },
            "operation": "cardinality",
        },
        {
            "value_id": "acc_recharge_amount",
            "target_value": "recharge_price",
            "value_name": "累计充值金额",
            "filter": [
                {"term": {"_event_id": "recharge"}}
            ],
            "time_range": {
                "_event_time": ['-', 0],
            },
        },
        {
            "value_id": "acc_profit_amount",
            "target_value": ["recharge_price", "-", "withdraw_real_price"],
            "value_name": "累计营收金额",
            "filter": [
                {'terms': {'_event_id': ['recharge', 'withdraw']}},
            ],
            "time_range": {
                "_event_time": ['-', 0],
            },
        },
        {
            "value_id": "acc_tax",
            "target_value": "tax_tax",
            "value_name": "累计税收",
            "filter": [
                {"term": {"_event_id": "tax"}}
            ],
            "time_range": {
                "_event_time": ['-', 0],
            },
        }
    ]
}
